package com.wing.member.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.member.model.entity.MemberRank;
import com.wing.member.service.MemberRankService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author
 */
@Api(value = "App-用户等级管理", tags = "用户等级管理")
@RestController("appMemberRankController")
@RequestMapping("member/app/memberRank")
public class MemberRankController {

    @Autowired
    private MemberRankService memberRankService;

    @GetMapping()
    public PageResult<MemberRank> list(){
        List<MemberRank> list = memberRankService.list(new QueryWrapper<MemberRank>().orderBy(true, false,"create_time"));
        return new PageResult<>(list);
    }

    @PostMapping()
    public JsonResult add(MemberRank memberRank) {
        if (memberRankService.save(memberRank)) {
            return JsonResult.success("添加成功");
        }
        return JsonResult.fail("添加失败");
    }

    @PutMapping()
    public JsonResult update(MemberRank memberRank) {
        if (memberRankService.updateById(memberRank)) {
            return JsonResult.success("修改成功！");
        }
        return JsonResult.fail("修改失败！");
    }

    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable("id") Long memberRankId) {
        if (memberRankService.removeById(memberRankId)) {
            return JsonResult.success("删除成功");
        }
        return JsonResult.fail("删除失败");
        }
    }
